cmake_minimum_required (VERSION 3.8)
project(LibDGGSField)
set(CMAKE_CXX_STANDARD 17)

if (MSVC)
    add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
endif ()
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
    set(DGGS_OUT_DIR ${CMAKE_OUT_DIR}/out/build/debug)
else ()
    set(DGGS_OUT_DIR ${CMAKE_OUT_DIR}/out/build/release)
endif ()


include_directories("${CMAKE_SOURCE_DIR}/LibDGGSBase")
include_directories("${CMAKE_SOURCE_DIR}/LibDGGSKernel")
link_directories("${DGGS_OUT_DIR}/LibDGGSKernel")

# 定义 INTERFACE 库
if (MSVC_VERSION GREATER_EQUAL 1930)  # 1930表示VS2022及以上版本
    add_library(LibDGGSField INTERFACE
            DGGSFieldLayer.hpp
            DGGSFieldBand.hpp
            DGGSFieldPartition.hpp
    )
else()
    add_library(LibDGGSField INTERFACE
    )
endif()

target_link_libraries(LibDGGSField INTERFACE
        LibDGGSKernelD
)

add_dependencies(LibDGGSField LibDGGSKernel)
if(ISEXTRACT)
    file(GLOB_RECURSE MyLIB_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp)
    foreach(header_file ${MyLIB_HEADERS})
        get_filename_component(header_dir ${header_file} DIRECTORY)
        string(REPLACE ${CMAKE_CURRENT_SOURCE_DIR} ${lib_output_directory}/include/LibDGGSField output_header_dir ${header_dir})
        file(MAKE_DIRECTORY ${output_header_dir})
        configure_file(${header_file} ${output_header_dir} COPYONLY)
    endforeach()
endif()

# 安装库和头文件
install(TARGETS LibDGGSField
        EXPORT LibDGGSFieldTargets
        PUBLIC_HEADER DESTINATION ${lib_install_directory}/include
)

install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/"
        DESTINATION ${lib_install_directory}/include
        FILES_MATCHING
        PATTERN "*.hpp"
)

install(EXPORT LibDGGSFieldTargets
        FILE LibDGGSFieldTargets.cmake
        NAMESPACE LibDGGSField::
        DESTINATION ${lib_install_directory}/cmake
)
